#ifndef __NETCVARS_H__
#define __NETCVARS_H__

#pragma once

#include "IConsole.h"
#include "Config.h"
#include "TimeValue.h"

#if USE_CRYLOBBY_GAMESPY
struct SFriendInfo;
struct SFriendManagementInfo;
#ifdef _RELEASE
#define GAMESPY_ENABLE_SESSION_PING	0
#else
#define GAMESPY_ENABLE_SESSION_PING	1
#endif
#endif

class CNetCVars
{
public:
	int TokenId;
	int CPU;
	int LogLevel;
	int CheatProtectionLevel;
	int EnableVoiceChat;
	int ChannelStats;
	float BandwidthAggressiveness;
	float NetworkConnectivityDetectionInterval; // disabled if less than 1.0f
	float InactivityTimeout;
	float InactivityTimeoutDevmode;
	float minMicrophonNotificationInterval;
	float serverPingNotificationInterval;
#if NETWORK_HOST_MIGRATION
	float hostMigrationTimeout;
	int netAutoMigrateHost;
	int showNewHostHinting;
	int showHostIdentification;
	int netHostHintingNATTypeOverride;
	int netHostHintingActiveConnectionsOverride;
	int netHostHintingPingOverride;
	int netPruneConnectionsAfterHostMigration;
	int netAnticipatedNewHostLeaves;
	int netAlternateDeferredDisconnect;
#if ENABLE_HOST_MIGRATION_STATE_CHECK
	int doHostMigrationStateCheck;
#endif
#endif
	int showMatchMakingTasks;
	int BackoffTimeout;
	int MaxMemoryUsage;
	int EnableVoiceGroups;
	int RTTConverge;
	int EnableTFRC;




















#if NET_ASSERT_LOGGING
	int AssertLogging;
#endif

	int PacketSendRate; // packets per second
	int NewQueueBehaviour;
	int SafetySleeps;
	int MaxPacketSize;
	float KeepAliveTime;
	float PingTime;

#if LOG_MESSAGE_DROPS
	int LogDroppedMessagesVar;
	bool LogDroppedMessages()
	{
		return LogDroppedMessagesVar || LogLevel;
	}
#endif

#if ENABLE_DEBUG_KIT
	int NetInspector;
	int MemInfo;
	int UseCompression;
	int ShowObjLocks;
	int DebugObjUpdates;
	int LogComments;
	int EndpointPendingQueueLogging;
	int DisconnectOnUncollectedBreakage;
	int DebugConnectionState;
	int RandomPacketCorruption; // 0 - disabled; 1 - UDP level (final stage); 2 - CTPEndpoint (before signing and encryption)
	//float WMICheckInterval;
	int PerfCounters;
	int GSDebugOutput;
#endif

	int VoiceLeadPackets;
	int VoiceTrailPackets;
	float VoiceProximity;

#if !ALWAYS_CHECK_CD_KEYS
  int CheckCDKeys;
#endif

	ICVar* StatsLogin;
	ICVar* StatsPassword;

  int RankedServer;

  int LanScanPortFirst;
  int LanScanPortNum;
	float MinTCPFriendlyBitRate;

	int useDeprecatedVoiceSystem;

	CTimeValue StallEndTime;

#if INTERNET_SIMULATOR
	float PacketLossRate;
	float PacketExtraLag;

	static void OnPacketLossRateChange(ICVar* NewLossRate)
	{
		if ( NewLossRate->GetFVal() < 0.0f )
			NewLossRate->Set(0.0f);
		else if ( NewLossRate->GetFVal() > 1.0f )
			NewLossRate->Set(1.0f);
	}

	static void OnPacketExtraLagChange(ICVar* NewExtraLag)
	{
		if ( NewExtraLag->GetFVal() < 0.0f )
			NewExtraLag->Set(0.0f);
		else if ( NewExtraLag->GetFVal() > 100.0f )
			NewExtraLag->Set(100.0f);
	}
#endif

#ifdef ENABLE_UDP_PACKET_FRAGMENTATION
	int net_max_fragmented_packets_per_source;
	float net_fragment_expiration_time;
	float PacketFragmentLossRate;
	static void OnPacketFragmentLossRateChange(ICVar* NewLossRate)
	{
		if ( NewLossRate->GetFVal() < 0.0f )
			NewLossRate->Set(0.0f);
		else if ( NewLossRate->GetFVal() > 1.0f )
			NewLossRate->Set(1.0f);
	}
#endif

	float HighLatencyThreshold; // disabled if less than 0.0f
	float HighLatencyTimeLimit;

#if USE_CRYLOBBY_GAMESPY
	int		lobbyGameSpyOnlinePort;
	int		connectionWaitTimeOut;
	int		gamespySymmetricalFriends;
#ifndef _RELEASE
	int		gamespyCheckCDKey;
#endif
#if GAMESPY_ENABLE_SESSION_PING
	int		gamespySessionPing;
#endif
#endif

	int		lobbyDefaultPort;

#if ENABLE_DEBUG_KIT
	int VisWindow;
	int VisMode;
	int ShowPing;
#endif

	ICVar * pVoiceCodec;
  ICVar * pSchedulerDebug;

#if LOG_INCOMING_MESSAGES || LOG_OUTGOING_MESSAGES
	int LogNetMessages;
#endif
#if LOG_BUFFER_UPDATES
	int LogBufferUpdates;
#endif
#if STATS_COLLECTOR_INTERACTIVE
	int ShowDataBits;
#endif

	int RemoteTimeEstimationWarning;

#if ENABLE_CRYLOBBY_DEBUG_TESTS
	int	cldErrorPercentage;
	int	cldMinDelayTime;
	int	cldMaxDelayTime;
	int	cldEnable;
#endif

#if ENABLE_CORRUPT_PACKET_DUMP
	int		packetReadDebugOutput;
	bool	doingPacketReplay()		{ return packetReadDebugOutput ? true : false; }
#else
	bool	doingPacketReplay()		{ return false; }
#endif
	
	// BREAKAGE
	int breakageSyncEntities;

#if USE_CRYLOBBY_GAMESPY
	int gamespySearchPingRetry;
	int gamespySearchPingTimeOut;
#endif

	int enableWatchdogTimer;

	static ILINE CNetCVars& Get()
	{
		NET_ASSERT(s_pThis);
		return *s_pThis;
	}

private:
	friend class CNetwork; // Our only creator

	CNetCVars(); // singleton stuff
	~CNetCVars();
	CNetCVars(const CNetCVars&);
	CNetCVars& operator= (const CNetCVars&);

	static CNetCVars* s_pThis;

	static void ReloadScheduler( IConsoleCmdArgs* );
	static void DumpObjectState( IConsoleCmdArgs* );
	static void DumpBlockingRMIs( IConsoleCmdArgs* );
	static void Stall( IConsoleCmdArgs* );
  static void SetCDKey( IConsoleCmdArgs* );
#if NETWORK_REBROADCASTER
	static void RebroadcasterCmd(IConsoleCmdArgs* pArgs);
#endif
#if NETWORK_HOST_MIGRATION
	static void EnsureBestHostForSessionCmd(IConsoleCmdArgs* pArgs);
#endif

#if USE_CRYLOBBY_GAMESPY
	static void GameSpyGetProfileIDCmd( IConsoleCmdArgs* pArgs );
	static void GameSpySendInviteCmd( IConsoleCmdArgs* pArgs );
	static void GameSpyAcceptInviteCmd( IConsoleCmdArgs* pArgs );
	static void GameSpyLogInvitesCmd( IConsoleCmdArgs* pArgs );
	static void GameSpyLogInvitesCallback( UCryLobbyEventData eventData, void *pUserParam );
	static void GameSpyListFriendsCmd( IConsoleCmdArgs* pArgs );
	static void GameSpyListFriendsCallback( CryLobbyTaskID taskID, ECryLobbyError error, SFriendInfo* pFriendInfo, uint32 numFriends, void* pArg );
	static void GameSpySendFriendRequestCmd( IConsoleCmdArgs* pArgs );
	static void GameSpyAcceptFriendRequestCmd( IConsoleCmdArgs* pArgs );
	static void GameSpyRevokeFriendStatusCmd( IConsoleCmdArgs* pArgs );
	static void GameSpyLogFriendEventsCmd( IConsoleCmdArgs* pArgs );
	static void GameSpyLogFriendEventCallback( UCryLobbyEventData eventData, void *pUserParam );
	static void GameSpyBlockProfile(IConsoleCmdArgs* pArgs);
	static void GameSpyUnblockProfile(IConsoleCmdArgs* pArgs);
	static void GameSpyIsProfileBlocked(IConsoleCmdArgs* pArgs);
	static void GameSpyIsProfileBlockedCallback(CryLobbyTaskID taskID, ECryLobbyError error, SFriendManagementInfo* pInfo, uint32 numUserIDs, void* pArg);
	static void GameSpyIsUserFriend( IConsoleCmdArgs* pArgs );
	static void GameSpyIsUserFriendCallback( CryLobbyTaskID taskID, ECryLobbyError error, SFriendManagementInfo* pInfo, uint32 numUserIDs, void* pCbArg );
	static void GameSpyGetName( IConsoleCmdArgs* pArgs );
	static void GameSpyGetNameCallback( CryLobbyTaskID taskID, ECryLobbyError error, SFriendInfo* pInfo, uint32 numUserIDs, void* pCbArg );
	static void GameSpyFindUser( IConsoleCmdArgs* pArgs );
	static void GameSpyFindUserCallback( CryLobbyTaskID taskID, ECryLobbyError error, SFriendInfo* pInfo, uint32 numUserIDs, void* pCbArg );
#endif
};

#endif
